package com.rybbaby.tss.front.tssAllocation.dao.imp;

import com.rybbaby.tss.core.web.dao.imp.GenericDao;
import com.rybbaby.tss.front.tssAllocation.dao.ITssAllocationDao;
import com.rybbaby.tss.front.tssAllocation.entity.TssAllocation;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @description 客户分配表数据库操作实现
 * 
 * @author 雷春琼
 * 
 * @createDate 2017-08-15 下午7:26:47
 */
@Repository
public class TssAllocationDaoImp extends GenericDao<TssAllocation> implements ITssAllocationDao {

    @Override
    public List<Map<String, Object>> getDetailListByMemberId(String memberId) throws Exception {
        String sql="SELECT\n" +
                "\tt2.id,\n" +
                "\tt2.empName,\n" +
                "\tt2.adminName,\n" +
                "\tstu.NAME AS stuName, \n" +
                "\tt2.createTime,\n" +
                "\tt2.version\n" +
                "FROM\n" +
                "\t(\n" +
                "SELECT\n" +
                "\tt1.*,\n" +
                "\tsysAdmin.realName AS adminName \n" +
                "FROM\n" +
                "\t(\n" +
                "SELECT\n" +
                "\tallocation.*,\n" +
                "\tsysEmp.realName AS empName \n" +
                "FROM\n" +
                "\ttss_allocation allocation\n" +
                "\tLEFT JOIN sys_admin_user sysEmp ON allocation.empAdminUserId = sysEmp.id \n" +
                "WHERE\n" +
                "\tallocation.studentId = ? \n" +
                "\t) AS t1\n" +
                "\tLEFT JOIN sys_admin_user sysAdmin ON t1.adminUserId = sysAdmin.id \n" +
                "\t) AS t2\n" +
                "\tLEFT JOIN tss_student stu ON t2.studentId = stu.id";
        List<Map<String, Object>> forJdbc = super.findForJdbc(sql, new String[]{memberId});
        return forJdbc;
    }

    @Override
    public List<TssAllocation> findByEmpAdminUserId(String empAdminUserId, String studentId) {
        String sql = "SELECT * from tss_allocation WHERE tss_allocation.studentId = '"+studentId+"' AND empAdminUserId='"+empAdminUserId+"'";
        return findListBySql(sql,TssAllocation.class,null);
    }
}
